package com.csun.nusing.ui.activity;

import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.csun.nusing.R;
import com.csun.nusing.bean.UrlBean;
import com.csun.nusing.bean.jsonbean.BaseJsonBean;
import com.csun.nusing.presenter.CommonPresenter;
import com.csun.nusing.ui.BaseActivity;
import com.csun.nusing.util.SPUtils;
import com.csun.nusing.util.ToastUtil;
import com.google.gson.Gson;
import com.home.administrator.okhttplibrary.IOkTaskCallback;
import com.home.administrator.okhttplibrary.OkHttpTask;

import java.util.HashMap;
import java.util.Map;

/**
 * 帮助中心
 * 作者: Created by fzq on 2018/2/11 13:38
 * 邮箱: 15997123593@163.com
 */
public class HelpCenterActivity extends BaseActivity<CommonPresenter> {


    private RelativeLayout toprl;
    private TextView helptv;
    private boolean isFamilyFlag;
    private EditText contentet;
    private EditText phoneet;
    private String content;
    private String phone;

    @Override
    public int getContentViewId() {
        return R.layout.activity_help_center;
    }

    @Override
    public void initSubViews(View view) {
        super.initSubViews(view);
        toprl = (RelativeLayout) findViewById(R.id.help_center_top_rl);
        helptv = (TextView) findViewById(R.id.help_center_send_tv);
        contentet = (EditText) findViewById(R.id.help_center_content_et);
        phoneet = (EditText) findViewById(R.id.help_center_phone_et);

        controlView();
    }

    private void send() {
        content = contentet.getText().toString().trim();
        phone = phoneet.getText().toString().trim();
        if (content == null || content.length() < 1) {
            ToastUtil.showMessage(this, "请填写内容");
            return;
        }
        String authorization = (String) SPUtils
                .get(this, "authorization", "");
        Map<String, String> param = new HashMap<String, String>();
        param.put("proposal", "" + content);
        param.put("logtype", "0");
        OkHttpTask.newInstance(this).post(param, OkHttpTask.OkHttpTaskBuidler.OkType.form)
                .addHeader("authorization", authorization)
                .enqueue(new IOkTaskCallback() {
                    @Override
                    public void onSuccess(String result) {
                        Gson gson = new Gson();
                        BaseJsonBean baseJsonBean = gson.fromJson(result,BaseJsonBean.class);
                        if (baseJsonBean.isStatus()){
                            ToastUtil.showMessage(HelpCenterActivity.this, "感谢您的建议");
                        }else{
                            ToastUtil.showMessage(HelpCenterActivity.this, baseJsonBean.getMessage());
                        }

                    }
                }).start(UrlBean.SUGGESTADDURL);
    }

    private void controlView() {
        helptv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                send();
            }
        });
    }


    @Override
    public void initData() {
        super.initData();
        isFamilyFlag = getIntent().getBooleanExtra("isFamily", false);
        if (isFamilyFlag) {
            toprl.setBackgroundResource(R.drawable.main_whiteyello_color_shape);
        } else {
            toprl.setBackgroundResource(R.drawable.main_whiteblur_color_shape);
        }
    }
}
